﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;
using System.IO;

public partial class controls_admin_GalleryDetails : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            loadData();
        }
    }
    private void loadData()
    {
        try
        {
            base.bindRepeater(rptAds, BO_portal_galleries_details.SelectByGallery(1, Page_size, 1, Convert.ToInt32(Request["GALLERY_ID"])), divMessage);
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi trong quá trình xử lý<br />" + ex.Message);
        }
    }
    protected string GetAds(string ads)
    {
        if (ads != "")
        {
            string strReturn = "";
            string extension = Path.GetExtension(ads);
            if (extension == ".swf")
                strReturn = "<object height=' 100' border='0' width='200' codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"><param value=\"" + ads + "\" name=\"movie\"><param value=\"always\" name=\"AllowScriptAccess\"><param value=\"High\" name=\"quality\"><param value=\"transparent\" name=\"wmode\"><param value=\"#\" name=\"FlashVars\"><embed  height=' 100' border='0' width='300' allowscriptaccess=\"always\" wmode=\"transparent\" loop=\"true\" play=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" flashvars=\"#\" src=\"" + ads + "\"></object>";
            else
            {
                if (!ads.StartsWith("http://"))
                    strReturn = "<img height='100' style='max-width:500px' src='/" + Setting.Path + ads + "' onerror='ImgError(sthis);' />";
                else
                    strReturn = "<img height='100' style='max-width:500px' src='" + ads + "' onerror='ImgError(sthis);' />";
            }
            return strReturn;
        }
        else
            return "";

    }
    protected void ddlAction_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (ddlAction.SelectedValue.Equals("0"))
                return;
            string selectedItems = GetSelectedItems(rptAds, "chkBox");
            if (String.IsNullOrEmpty(selectedItems))
            {
                Javascripts.Alert(Page, "Phải chọn ít nhất 1 module!");
                return;
            }
            if (BO_portal_galleries_details.Delete(selectedItems, ";", Convert.ToInt32(ddlAction.SelectedValue)))
            {
                divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Thực hiện thành công.");
            }
            else
            {
                divMessage.InnerHtml = MessageBox.Error("Lỗi", "Chưa thực hiện được !");
            }
            loadData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi hệ thống", "Phát hiện lỗi sau: " + ex.Message);
        }
    }

}
